'use strict';

/**
 * model.js
 * instead of init the model inside the index.js file
 * we could take care of that here. Then just export a db instance back.
 * This way we further abstract away the tie between app and database backend
 */
var config = require('./config'),
    umzug = require('umzug'), // https://github.com/sequelize/umzug <-- for migration [TODO]
    chalk = require('chalk'),
	Sequelize = require('sequelize'),
	db = module.exports;
/**
// the construct look like this
// 'postgres://user:pass@example.com:5432/dbname'
// [driver]://[username]:[password]@[url]:[port]/[database name]
only when it is a sqlite
var sequelize = new Sequelize(DATABASE_NAME, DATABASE_USER, DATABASE_PASS, {
    dialect: 'sqlite',
    storage: DATABASE_PATH
});
**/
try {

	db = new Sequelize(<% if (answers.useSqlite) { %>config.db.options.name , config.db.options.user , config.db.options.pass , {dialect: 'sqlite', storage: config.db.options.path}<% } else { %>config.db.uri , config.db.options<% } %>);
} catch(e) {
	console.log(chalk.red('Database connection error:' , e));
	process.exit(-1);
}
